Web API Request and Response - Example

This topic has been written to provide you with a detailed, step-by-step example of how to import a Web APIClosed A Web API is an application programming interface (API) for either a web server or a web browser, and consists of publicly exposed endpoints to a defined request-response message system, typically expressed in JSON or XML by means of an HTTP-based web server. into Digitise Forms, and how to send a requestClosed An HTTP 'Request' is sent from a client to a host located on a server in order to receive the resource that it needs to build content. and receive a responseClosed An HTTP 'Response' is sent by a server to a client with the aim of providing the client with the resource it requested. using two of the Web API's operationsClosed An operation is a unit of a REST API which can be called and which comprises of an HTTP verb and a URL path..

 

Once you have imported the sample Web API and its operations, you should be able to map, retrieve, and view data from the target remote resource within your Forms project.

 

For this example, we will be using the Petstore Web API - available from the Swagger website (https://petstore.swagger.io). This particular Web API allows pet information to be retrieved, new pet records to be added, and existing pet records to be amended or deleted etc. on a live server.

  • Although the Web API will be fully functional in terms of allowing requests to be sent and responses to be received, it isn't an exact copy of Swagger's unabridged Petstore Web API. For our purposes, the Petstore Web API has been adapted slightly in order to reduce complexity and to limit the number of available operations. Also note that because the Petstore Web API is a 'real-world', publicly accessible Web API used for testing and experimentation purposes, pet-related information can be changed and records can be added or removed by non-NDL clients using their own systems or applications (provided the correct pet information (e.g., a valid Pet ID) has been used).

We will be adding a new pet to the pet store using the addPet operation, and we will then retrieve the newly-added pet information using the getPetById operation. The relevant request fields will be populated at form runtime and a button will then be clicked in order to make the web services request. A second button will then be pressed in order to retrieve the new pet details, which will populate the configured response fields.

 

Before following the steps detailed below, we would advise that you read through the remainder of the Connect topics within this Online Help in order to familiarise yourself with the terminology used. To avoid repetition, this topic will only discuss the options that you need to select in order to import the Petstore Web API and its addPet and getPetById operations (the full range of available options is covered in full in the other Connect topics). You may need to select different options when importing one of the other pre-configured Web APIs, so if you work through this example and then try to import a different Web API, you may find that you need to re-read the other Connect topics in order to obtain the relevant information. Links to other topics have been provided for reference purposes where appropriate, but you won't need to click on any of those links or navigate away from this page in order to successfully implement the Petstore Web API.

  • In order to access the Petstore Web API and make use of the addPet and getPetById operations, the Web API's OpenAPI definitionClosed A file used to interpret and interact with a Web API (usually in YAML or JSON format). must already have been imported using Hub Manager. The addPet and getPetById operations must also have had their Enabled/Disabled and Public/Private properties configured to allow them to process requests and to make them available for selection within Digitise Forms when the Web API is being imported. To find out more about importing OpenAPI definitions and configuring their properties, see the Connect topics within the separate Hub Online Help.

The form which you will be creating contains several navigation buttons for moving between its pages and for selecting different options. You may decide, after following this example, to adapt your completed web services project so that it doesn't use buttons in the way they have been implemented here. You may also decide to enhance (or even abandon) the validation for a successful web service request using custom JavaScript, or to include more (or less) pages, depending on your requirements. The core functionality - making a web service request using Connect and mapping response data - should, however, be retained as outlined in the following steps, but the order and position of pages and form Elements is a matter of personal choice. As long as you are able to add a pet and retrieve pet details within a single form, any navigation or supplementary styling and design features which have been incorporated into this example (e.g., the form header; text box and button labels and colours; spacing between form Elements; form section sub-headings etc.) can be adapted, included, or excluded, as you see fit.

  • When you add an Element (such as a Text Box) to your form, you can change most of the Element's properties, including the Element's Name and Label text, if required. See the Using Elements topic for more information.

Remember to periodically save your changes as you progress through the form setup.

 

 


See also:

Connect

Connect Overview

Web API Connectors

Import Web API Connectors